package com.kpatil.erp.core.measure;

import com.kpatil.erp.common.HasName;

public abstract class UnitOfMeasure implements HasName {

	/**
	 * Combination of name and type should be unique , i.e Primary Key
	 */
	private String name;
	private UnitType type;
	private double precision = 0.0010d;

	@Override
	public final String getName() {
		return name; 
	}

	public final void setName(String name) {
		this.name = name;
	}

	public final void setPrecision(double precision) {
		this.precision = precision;
	}

	public final double getPrecision() {
		return precision;
	}

	public final void setType(UnitType type) {
		this.type = type;
	}

	public final UnitType getType() {
		return type;
	}

	public abstract double getUnit();

	@Override
	public final String toString() {
		return getName() + "[" + getType() + "]";
	}

	@Override
	public final int hashCode() {
		return toString().hashCode();
	}

	@Override
	public final boolean equals(Object object) {
		if (object instanceof UnitOfMeasure) {
			return this.hashCode() == object.hashCode();
		} else {
			return false;
		}

	}
}
